<!DOCTYPE html>
<html>
<head>
	<title>登陆功能</title>
	<style type="text/css">
		img{
			width:100px;
		}
	</style>
	  {load href="/static/js/jquery-1.7.2.min.js" /}
</head>
<body>
	<form action="" method="post" name="forminfo">
		<input type="text" name="sname" placeholder="用户名"><br>
		<input type="password" name="pwd" placeholder="密码"><br>
		<input type="text" name="captcha" placeholder="验证码"><span id="check_captcha"></span><br>
		{:captcha_img()}<br>
		<input type="submit" name="sub" value="登陆">
	</form>
	<script type="text/javascript">
		var i='';
		function checkcaptcha(v){
			if(v!=''){
				$.post("{:url('index/index/index')}","captcha="+v,function(res){
					if(res.code==1){
						$("#check_captcha").css("color","green");
						$("#check_captcha").html(res.msg);
						console.log(res.code);
						i=true;
					}else{
						$("#check_captcha").css("color","red");
						$("#check_captcha").html(res.msg);
						i=false;
					}
				})
				return i;
			}else{
				$("#check_captcha").css("color","red");
				$("#check_captcha").html("验证码不能为空");
				return false;
			}
		}
		$("input[name=captcha]").blur(function(){
			var v=$(this).val();
			checkcaptcha(v);
		})
		$("img[alt=captcha]").click(function(){
			var src="/captcha.html?t="+Math.random();
			$(this).attr("src",src);
		})
		$("form[name=forminfo]").submit(function(){
			var v=$("input[name=captcha]").val();
			//console.log(v);
			return checkcaptcha(v);
		})
	</script>
</body>
</html>